package com.itboye.sunsun.me.ui;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.sunsun.adapter.SystemAnnounceAdapter;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.KefuUIBeans;
import com.itboye.sunsun.beans.KefuUIBeans.KeFuBeans;
import com.itboye.sunsun.beans.MessageBean;
import com.itboye.sunsun.beans.SttingTelBeans;
import com.itboye.sunsun.beans.WoDeZhuTiBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.custome.XListView;
import com.itboye.sunsun.custome.XListView.IXListViewListener;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.support.BaseFragment;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;
import com.itboye.sunsunhome.R;

public class KeFuMeFragment extends BaseFragment {

	private XListView xlistviewMessge;
	private int pageNum = 1;
private RelativeLayout title_tbae;
	private BaseAdapter adapter;

	
	private TextView tvMessge,textStrimg;
	List<KeFuBeans> dataList = new ArrayList<KeFuBeans>();
LinearLayout layoutNull;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_messge, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
//		tvMessge.setText(R.string.xitong_messge);
		title_tbae.setVisibility(View.GONE);
		xlistviewMessge.setPullRefreshEnable(false);
		xlistviewMessge.setPullLoadEnable(false);

		adapter = new KeFuAdapter(dataList);
		xlistviewMessge.setAdapter(adapter);

		pullDown();

	
	}

	private void pullDown() {
		
		int page_num=1;
		int page_size=10;
		String uid = (String) SPUtils.get(App.ctx, null, SPContants.USER_ID,
				"");
		MyJsonRequest.Builder<KefuUIBeans> builder = new MyJsonRequest.Builder<KefuUIBeans>()
				.apiVer("100").typeKey("BY_Customer_servicehis")
				.param("uid", uid)
				.param("page_no",page_num)
				.param("page_size",page_size)
				.requestListener(new XRequestListener<KefuUIBeans>() {

					@Override
					public void onResponse(final KefuUIBeans bean) {

							

							dataList.clear();
							if(bean.getList()!=null){
								dataList.addAll(bean.getList());
								adapter.notifyDataSetChanged();
							}
							if(adapter==null || bean.getList()==null){
								layoutNull.setVisibility(View.VISIBLE);
								xlistviewMessge.setVisibility(View.GONE);
								textStrimg.setText("暂无客服消息");
							}
					}

				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {
						// onPullDownError(adapter, xlistview, exception, code,
						// msg);
					}
				});

		MyJsonRequest<KefuUIBeans> request = builder.build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}


	

}
